home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / NOTIFY_M / STARTUPE.C next >
Text File  |  1992-07-19  |  3KB  |  152 lines

  1. /**-------------------------------------------------------------------------
  2.  **
  3.  ** Include Files
  4.  **
  5.  **/
  6.  
  7. #include "StartupError.h"
  8.  
  9.  
  10. /**-------------------------------------------------------------------------
  11.  **
  12.  ** Private Macros
  13.  **
  14.  **/
  15.  
  16. /**
  17.  
  18.     T_NMInstall and T_Unimplemented are Mac toolbox trap numbers used to
  19.     test for the existence of the Notification Manager.
  20.  
  21.  **/
  22.  
  23. #define T_NMInstall            (0xA05E)
  24. #define T_Unimplemented        (0xA89F)
  25.  
  26. /**
  27.  
  28.     STARTUP_ERROR_STR_ is the resource ID of the STR# containing the
  29.     error message corresponding to the error number passed to
  30.     StartupError().
  31.  
  32.     RESPONSE_RESP is the resource ID of the RESP code resource compiled
  33.     separately and stuck in your INIT's resources.
  34.  
  35.  **/
  36.  
  37. #define STARTUP_ERROR_STR_    (128)
  38. #define RESPONSE_RESP        (128)
  39.  
  40.  
  41. /***************************************************************************
  42.  ***
  43.  *** void    StartupError(int errorNumber);
  44.  ***
  45.  *** When your INIT runs into a problem, clean things up, show the X'ed
  46.  *** version of your icon and call StartupError() with an error number
  47.  *** corresponding to the message you want displayed.
  48.  ***
  49.  *** History:
  50.  ***    jhh 18 jun 90 -- response to news posting
  51.  ***    pls 09 sep 91 -- minor change for C 4 & 5 compatibility
  52.  ***
  53.  ***/
  54.  
  55. void
  56. StartupError(int errorNumber)
  57. {
  58.     register NMRec    *note;
  59.     register Handle    responseCode;
  60.     register long    size;
  61.     register THz    svZone;
  62.     Str255            errorText;
  63.  
  64. /**
  65.  
  66.     Make sure we've got a Notification Manager.
  67.  
  68.  **/
  69.  
  70.     if (NGetTrapAddress(T_NMInstall, OSTrap) !=
  71.         NGetTrapAddress(T_Unimplemented, ToolTrap)) {
  72.  
  73. /**
  74.  
  75.     All of the memory we allocate from here on out is in the System
  76.     Heap.  First create a Notification Manager record and fill it in.
  77.     Note that you can expand this notification method with sounds and
  78.     icons by adding the appropriate code.  See the Notification
  79.     Manager technote #184 for details.
  80.  
  81.  **/
  82.  
  83.         svZone = TheZone;
  84.         TheZone = SysZone;
  85.         note = (NMRec *)NewPtrClear(sizeof(NMRec));
  86.         if (!note)
  87.             goto exit;
  88.         note->qType = nmType;
  89.         note->nmSound = (Handle)-1;
  90.  
  91. /**
  92.  
  93.     Get the error message corresponding to the error number given.
  94.     For maximum performance, the STR# resource should be tagged
  95.     "Preload" and not "System Heap".  This way, you can be sure
  96.     the messages will be there even if memory space is the cause of
  97.     the error.
  98.  
  99.     We create a pointer in the System Heap just big enough for the
  100.     string and copy the string into it.  Point the NM record at this
  101.     string.
  102.  
  103.  **/
  104.  
  105.         GetIndString(errorText, STARTUP_ERROR_STR_, errorNumber);
  106.         size = *(unsigned char *)errorText;
  107.         note->nmStr = (StringPtr)NewPtr(size);
  108.         if (!note->nmStr) {
  109.             DisposPtr(note);
  110.             goto exit;
  111.         }
  112.         BlockMove(errorText, note->nmStr, size);
  113.  
  114. /**
  115.  
  116.     The response procedure also must be in a pointer in the System
  117.     Heap.  You need to include the compiled code resource in your
  118.     INIT's resources of type 'RESP'.
  119.  
  120.     Create a pointer just big enough for it and point the NM record
  121.     at it, also.
  122.  
  123.  **/
  124.  
  125.         responseCode = GetResource('RESP', RESPONSE_RESP);
  126.         if (!responseCode) {
  127.             DisposPtr(note->nmStr);
  128.             DisposPtr(note);
  129.             goto exit;
  130.         }
  131.         size = GetHandleSize(responseCode);
  132.         note->nmResp = (ProcPtr)NewPtr(size);
  133.         if (!note->nmResp) {
  134.             DisposPtr(note->nmStr);
  135.             DisposPtr(note);
  136.             goto exit;
  137.         }
  138.         BlockMove(*responseCode, note->nmResp, size);
  139.  
  140. /**
  141.  
  142.     Now post the note.  As soon as startup is complete, the NM
  143.     will display the note for the user's edification.  Hurrah.
  144.  
  145.  **/
  146.  
  147.         NMInstall(note);
  148. exit:
  149.         TheZone = svZone;
  150.     }
  151. }
  152.